package br.com.lpoint.job.dao;

import java.util.List;

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import br.com.lpoint.job.model.JobAgendado;

@Stateless
@Local(value=JobDAO.class)
public class JobDAOImpl implements JobDAO {
	
	@PersistenceContext(unitName="lpoint")
	private EntityManager entityManager;

	@Override
	public List<JobAgendado> hasJobParaRodar() {
		System.out.println("Executando o hasJobParaRodar com " + entityManager);
		Query query = entityManager.createQuery("SELECT job FROM JobAgendado job");
		List<JobAgendado> jobs = query.getResultList();
		System.out.println("Jobs retornados, size: " + jobs.size());
		return jobs;
		
	}

}
